$(function () {
	
	// 分页参数条件
	function queryParams() {
		var param = {
	        className : $("#className").val(),
	        productId : $("#productId").val(),
	        pageNum : this.pageNumber,
	        pageSize : this.pageSize
	    }
	    return param;
	}
	
	// 响应消息处理
	function responseHandler(res) {
		if (res) {
	        return {
	            "rows" : res.rows,
	            "total" : res.total
	        };
	    } else {
	        return {
	            "rows" : [],
	            "total" : 0
	        };
	    }
	}
	
	function operateFormatter(value, row, index) {
        return [
            '<a class="select" href="javascript:void(0)" title="选择">',
            '<i class="glyphicon glyphicon-check">选择</i>',
            '</a>  '
        ].join('');
    }

    var operateEvents = {
        'click .select': function (e, value, row, index) {
            $("input[name='classes.name']").val(row.name);
            $("#classSelect").modal("hide");
        }
    };
	
	$("#classForm").bootstrapTable({
		method:'GET',
		dataType:'json',
		contentType:"application/json",
		cache: false,
        striped: true,					// 是否显示行间隔色
        sidePagination: "server",		// 服务端分页
        url:"class/lists",
        pagination:true,
        queryParams : queryParams,
        pageNumber:1,					// 初始化加载第一页，默认第一页
        pageSize: 10,					// 每页的记录行数（*）
        pageList: [10, 25, 50, 100],	// 可供选择的每页的行数（*）
        showExport: false,                    
        responseHandler: responseHandler,
        columns: [
        	{
        		field: "name",
        		title: "班级名称",
        		align : "center",
                valign : "middle"
        	},
        	{
        		field: "remarks",
        		title: "班级备注",
        		align : "center",
                valign : "middle"
        	},
        	{
        		title: "操作",
        		align : "center",
                valign : "middle",
                events: operateEvents,
                formatter: operateFormatter
        	}
        ]
	});
	
	$("button.selectClass").click(function () {
		$("#classForm").bootstrapTable("refresh");
	});
	
	$("#student-form").validate({
		errorElement : "label",  
        errorClass : "text-danger",  
        rules : {
        	id : {
            	required : true,
            	minlength: 2,
            	maxlength: 50
            },
            name: {
                required : true,
                minlength: 2,
            	maxlength: 10
            },  
            sex: {  
                required : true,
            	maxlength: 1
            },  
            textBoxId: {  
            	maxlength: 20
            },  
            tel: {  
                required : true,
            	maxlength: 50
            },  
            "education.value": {  
                required : true,
            	digits : true
            },  
            school: {  
                required : true,
            	maxlength: 100
            },  
            emergent: {  
            	maxlength: 50
            },  
            emergentContact: {  
            	maxlength: 50
            },  
            previousJob: {  
            	maxlength: 50
            },  
            joinWay: {
            	maxlength: 20
            },  
            joinDate: {  
                dateISO:true
            },
            intentionalCity: {  
                required : true,
            	maxlength: 50
            },
            email: {  
                required : true,
                email:true
            },  
            passCheck: {  
                required : true,
            	maxlength: 50
            },  
            jobIntention: {  
            	maxlength: 500
            },  
            abnormal: {  
            	maxlength: 500
            },  
            evaluate: {  
            	maxlength: 500
            },  
            remarks: {
            	maxlength: 500
            },  
            "classes.name": {
            	maxlength: 30
            },
            address: {  
                required : true,
            	maxlength: 500
            },
            idNumber: {
            	required : true,
            	minlength: 15,
            	maxlength: 18
            },
            major: {
            	required : true,
            	maxlength: 20
            }
        }
	});
	
	// 初始化日期控件
	$(".datetimepicker").datetimepicker({
	    format: 'yyyy-mm-dd',
	    minView: 2,
	    autoclose: true,
	    language: "zh-CN",
	    clearBtn: true
	});
});